
//
//  MyTopView.m
//  OwnerNews
//
//  Created by lanou3g on 15/8/30.
//  Copyright (c) 2015年 Drawzyn. All rights reserved.
//

#import "MyTopView.h"
#import "FindingManager.h"
#import "FindTopImage.h"
#import "UIImage+ImageDownLoader.h"
#import "DiscoverViewController.h"
#import "TopViewController.h"

@implementation MyTopView


-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self DrawMySelfView];
       
    }
    return self;
}

-(void)DrawMySelfView {
    
    self.backgroundColor = [UIColor orangeColor];
    
    
    _LscrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.bounds), 180)];
    _LscrollView.contentSize = CGSizeMake(CGRectGetWidth(self.bounds) * 3,160);
    _LscrollView.backgroundColor = [UIColor orangeColor];
    _LscrollView.pagingEnabled = YES;
    _LscrollView.bounces = NO;
    _LscrollView.showsHorizontalScrollIndicator = NO;
    
    [self addSubview:_LscrollView];
    
    [self GetMyHeight];
    
    for (NSInteger i = 0; i < 3; i ++) {
        
        FindTopImage *FTP = [FindingManager defaultManager].FindTopArray[i];
        [UIImage downLoaderImageWithURL:FTP.image andBlock:^(UIImage *image) {
            _LImgView = [[UIImageView alloc]initWithFrame:CGRectMake(self.bounds.size.width * i, 0, self.bounds.size.width, self.LscrollView.frame.size.height)];
            _LImgView.backgroundColor = [UIColor cyanColor];
            _LImgView.image = [UIImage imageNamed:@"b"];
            _LImgView.image = image;
            
            _LImgView.userInteractionEnabled = YES;
            
            [self.LscrollView addSubview:_LImgView];
            
            
            _LLabel = [[UILabel alloc]initWithFrame:CGRectMake(0 + self.bounds.size.width * i, 160, self.bounds.size.width/2, 20)];
            _LLabel.text = FTP.title;
            [self.LscrollView addSubview:_LLabel];
        }];
    }
    _PageControl  = [[UIPageControl alloc]initWithFrame:CGRectMake(self.bounds.size.width / 2 + 60, 160, self.bounds.size.width / 2 - 60, 20)];
    _PageControl.numberOfPages = _LscrollView.contentSize.width/CGRectGetWidth(self.bounds);
    [self addSubview:_PageControl];
    
//    for (NSInteger i = 0; i < 4; i ++) {
//        FindBtnMessage *FBM = [FindingManager defaultManager].FindMidArray[i];
//        [UIImage downLoaderImageWithURL:FBM.icon andBlock:^(UIImage *image) {
//            _Mbutton = [[UIButton alloc]initWithFrame:CGRectMake(30 + 80 * i, 185, 70, 70)];
//            NSInteger tabs = 1000 + i;
//            _Mbutton.tag = tabs;
//            
//            //NSLog(@"%ld",_Mbutton.tag);
//            _Mbutton.layer.cornerRadius = 35;
//            [_Mbutton setImage:image forState:UIControlStateNormal];
//            //_Mbutton.imageView.userInteractionEnabled = YES;
//            [self.Mbutton addTarget:self action:@selector(TopButtonTouchAction:) forControlEvents:UIControlEventTouchUpInside];
//            [self addSubview:_Mbutton];
//            
//            _btnTitleLabel = [[UILabel alloc]initWithFrame:CGRectMake(30 + 80 *i, 185 + self.Mbutton.frame.size.height, 70, 30)];
//            _btnTitleLabel.text = FBM.title;
//            _btnTitleLabel.textAlignment = NSTextAlignmentCenter;
//            
//            [self addSubview:_btnTitleLabel];
//            
//        }];
//    }
}

- (CGFloat)GetMyHeight {
    CGFloat a = _LscrollView.frame.size.height;
    return a;
}


/**
 *  中部功能按钮点击方法
 *
 *  @param sender 按钮对象
 */
- (void)TopButtonTouchAction:(UIButton *)sender {
    if (sender.tag == 1000) {
         NSLog(@"这是循环的第一个按钮");
    }
    if (sender.tag == 1001) {
         NSLog(@"这是循环的第二个按钮");
    }
    if (sender.tag == 1002) {
         NSLog(@"这是循环的第三个按钮");
    }
    if (sender.tag == 1003) {
         NSLog(@"这是循环的第四个按钮");
    }
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
